package notifiers;
 
import play.*;
import play.data.validation.*;
import play.db.jpa.Model;
import play.mvc.*;

import java.io.UnsupportedEncodingException;
import java.util.*;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
 
public class Mails extends Mailer {
	
	/**
	 * 
	 * method that send an email sharing a plan/request/idea
	 *
	 * @author		Amr Draz
	 * @version		2011.0428
	 * @category	C4S9
	 * @parameter 	sender: the person sharing
	 * 				emailTo: the mail that is being shared too
	 * 				content: a message the sender includes
	 * 				path: the url to the shared idea/plan/request
	 * return		boolean: whether the message was sent or not
	 */
	
	//waiting for SMTP to be configured
	public static boolean share(String sender,@Required String emailTo,@Required String content, String path){
		
		String body = content +"<br /><br /> see " + path;
		
		try {
			setFrom(new InternetAddress("noreply@gmail.com", "System"));
		setSubject("%s wanted to share this with you", ((sender == null)?"someone":sender));
		addRecipient(new InternetAddress(emailTo));
		setContentType("text/plain");
		
		setContentType("text/html");

		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AddressException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sendAndWait(sender, body);
	}

}
